﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MLSharp.Filters
{
	/// <summary>
	/// This filter will remove any instance that has a missing value
	/// from the data set.
	/// </summary>
	public class MissingDataRemoverFilter : IDataSetFilter
	{
		/// <summary>
		/// Removes all instances with a missing value from the data set.
		/// </summary>
		/// <param name="dataSet">The data set to transform.</param>
		public void Transform(IDataSet dataSet)
		{
			for (int i = 0; i < dataSet.Instances.Count; i++)
			{
				foreach (double value in dataSet.Instances[i].Values)
				{
					if (double.IsNaN(value))
					{
						dataSet.Instances.RemoveAt(i);
						break;
					}
				}
			}
		}
	}
}
